package com.crazy.entity.sys;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.LAZY;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.GenericGenerator;

/**
 * 角色 entity.
 * 
 * @author MyEclipse Persistence Tools
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "pub_role", uniqueConstraints = @UniqueConstraint(columnNames = "role_name"))
public class PubRole implements java.io.Serializable {
	private String roleId;
	private String roleName;
	private String roleDesc;
	private Integer enabled;
	private String creator;
	private Date createTime;
	private List<PubUser> pubUsers = new ArrayList<PubUser>(0);
	private List<PubResource> pubResources = new ArrayList<PubResource>(0);

	/** default constructor */
	public PubRole() {
	}

	@Id
	@Column(name = "role_id", unique = true, nullable = false, length = 32)
	@GenericGenerator(name = "generator", strategy = "uuid")
	@GeneratedValue(generator = "generator")
	public String getRoleId() {
		return this.roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	@Column(name = "role_name", unique = true, length = 100)
	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	@Column(name = "role_desc", length = 1000)
	public String getRoleDesc() {
		return this.roleDesc;
	}

	public void setRoleDesc(String roleDesc) {
		this.roleDesc = roleDesc;
	}

	@Column(name = "enabled")
	public Integer getEnabled() {
		return this.enabled;
	}

	public void setEnabled(Integer enabled) {
		this.enabled = enabled;
	}

	@Column(name = "creator", length = 100)
	public String getCreator() {
		return this.creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@Column(name = "create_time", length = 19)
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@ManyToMany(cascade = ALL, fetch = LAZY, mappedBy = "pubRoles")
	public List<PubUser> getPubUsers() {
		return this.pubUsers;
	}

	public void setPubUsers(List<PubUser> pubUsers) {
		this.pubUsers = pubUsers;
	}

	@ManyToMany(fetch = LAZY)
	@JoinTable(name = "pub_role_resource", joinColumns = { @JoinColumn(name = "role_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "resource_id", nullable = false, updatable = false) })
	public List<PubResource> getPubResources() {
		return this.pubResources;
	}

	public void setPubResources(List<PubResource> pubResources) {
		this.pubResources = pubResources;
	}
}